Converts a model_spec to a formula object. Unlike
stats::reformulate, this function handles complex response strings
(e.g. "Surv(time, event)", "log(y)") correctly by parsing
them as R expressions rather than coercing them to symbols. Parts set with
set_parts are included after |.
Examples
to_formula(model_spec(cyl, disp))
#> ~cyl + disp
#> <environment: 0x62b099dd4088>
to_formula(model_spec(cyl, disp), response = "mpg")
#> mpg ~ cyl + disp
#> <environment: 0x62b099ba7778>
to_formula(model_spec(cyl, disp), response = "Surv(time, event)")
#> Surv(time, event) ~ cyl + disp
#> <environment: 0x62b099b62300>
to_formula(model_spec(cyl, intercept = FALSE), response = "mpg")
#> mpg ~ 0 + cyl
#> <environment: 0x62b099b198d0>